In this Markdown document the 2SFCA methodology is implemented on the example of accessibility to hospitals for the citizens of the City of Zurich.
We will use three R packages.
Sf for managing spatial data. tmap for visualizations. cppRouting for calculating isochrones for points of interest.
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
Demographic data - GIUZ server
## Reading layer `stzh.adm_stadtkreise_a_polygon' from data source `C:\Users\Ivor\Documents\R\Projects\2SFCA\Data\kreise\data\stzh.adm_stadtkreise_a_polygon.shp' using driver `ESRI Shapefile'
## Simple feature collection with 12 features and 4 fields
## geometry type: POLYGON
## dimension: XY
## bbox: xmin: 2676225 ymin: 1241584 xmax: 2689666 ymax: 1254306
## projected CRS: CH1903+ / LV95
## Reading layer `stzh.poi_spital_view_point' from data source `C:\Users\Ivor\Documents\R\Projects\2SFCA\Data\spital\data' using driver `ESRI Shapefile'
## Simple feature collection with 125 features and 52 fields
## geometry type: POINT
## dimension: XY
## bbox: xmin: 2679827 ymin: 1244823 xmax: 2685967 ymax: 1251932
## projected CRS: CH1903+ / LV95
## Warning: attribute variables are assumed to be spatially constant throughout all
## geometries
## Reading layer `TBA_STR_ACHS_L' from data source `C:\Users\Ivor\Documents\R\Projects\2SFCA\Data\MSc\Strassenentz\strasen\Strassennetz\TBA_STR_ACHS_L.shp' using driver `ESRI Shapefile'
## Simple feature collection with 2614 features and 10 fields
## geometry type: LINESTRING
## dimension: XY
## bbox: xmin: 2668981 ymin: 1239533 xmax: 2693057 ymax: 1258605
## projected CRS: CH1903+ / LV95
## tmap mode set to interactive viewing
## Legend for symbol sizes not available in view mode.
Before we can implement the 2sfca, the data has to be of an appropriate format and depth. We need to prepare the road network dataset for calculating isochrones; catchment areas reachable from a location within a given time budget and network speeds.
The implementation of isochrones will be done using the cppRouting package which integrates the theories of Edger Dijkstra, who worked with and developed graph theory applications in computer science. The Dijkstra algorithm is used for routing between points on a network and is well established in transport sciences; and subsequently, very efficient. The cppRouting package integrates it with R and with some workarounds, we can implement it with spatial data.
Before we can develop isochrones we cannot do the 2SFCA methodology.
Furthermore, for proper isochronal analysis we need to know, for each service and demand point, what is the closest road and “snap” this point of interest to that road.
The road network is a list of all roads with their geometry. We have to find where do the geometries interesct and declare these intersections as a vertex per the graph theory (a graph is a set of edges and vertices). We have to save in the road network the start and end vertex of a road (edge) as the index of the vertices in a separate spatial data frame. The vertices dataframe will contain the PK (the index) and the X and Y coordinate of the vertex.
In our dataset, every start and end coordinate of a line is a vertex. We need to extract these, assign them a unique ID, and record which edges share them to remove duplicates.
## tmap mode set to interactive viewing
Now that we know the vertices of our transport network, we need to snap populations and hospitals to the nearest vertex. Alternatively (e.g. with network analyst in ARcGIS), the snapping can be done to the nearest edge. However, the cppRouting package uses vertices as the starting points for calculating isochrones.